<!DOCTYPE html>
<style>
h1 {
  font-family: sans-serif;
}
#postWarning {
  color: red;
}
textarea {
  width: calc(100%% - 10px);
  height: 50vh;
}
.item {
  font-weight: bold;
}
.item:before {
  content: '>>> ';
}
</style>

<h1>%(host)s CQ Status</h1>
<pre>
Source code:
<a href="https://chromium.googlesource.com/infra/infra/+/master/appengine/chromium_cq_status/">https://chromium.googlesource.com/infra/infra/+/master/appengine/chromium_cq_status/</a>
Use "<a href="http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html">fetch</a> infra" to clone the dev repos.



Site directory listing:

<span class="item"><a href="/recent">/recent</a></span>
Example: <a href="/recent#project=chromium,action=patch_start">/recent#project=chromium,action=patch_start</a>
Shows a table of recently received records.
Tags to filter by are specified as a comma separated list after the #.


<span class="item">/v2/patch-status/&lt;codereview_hostname&gt;/&lt;issue&gt;/&lt;patchset&gt;</span>
Example: <a href="/v2/patch-status/codereview.chromium.org/1067633003/1"
         >/v2/patch-status/codereview.chromium.org/1067633003/1</a>
Shows a log of CQ activity on a given patch.
Only accepts GET requests.


<span class="item">/post</span>
API for posting CQ records.
Requires @chromium.org/@google.com <a href="%(login_url)s">sign in</a>.
Only accepts POST requests.
Accepts multiple p URL params.
Each p value is a record to add in the following JSON structure:
{
  "key": str|null,
  "tags": [str],
  "fields": {field: value}
}
"project" is a required key in "fields".


TESTING ONLY:
<form id="queryForm">
Query entries from /query:
  key: <input type="textbox" name="key">
  begin: <input type="textbox" name="begin">
  end: <input type="textbox" name="end">
  tags: <input type="textbox" name="tags">
  fields: <input type="textbox" name="fields">
  count: <input type="textbox" name="count">
  cursor: <input type="textbox" name="cursor">
  <input type="reset" value="Clear"> <input type="button" id="querySubmit" value="Query">
</form>
Query view:
<textarea id="queryResult"></textarea>

<form id="postForm">
Post entry to /post:
  key: <input type="textbox" name="key">
  tags: <input type="textbox" name="tags">
  fields: <input type="textbox" name="fields">
  <input type="reset" value="Clear"> <input type="button" id="postSubmit" value="Post"> <span id="postWarning"></span>
Post result:
<textarea id="postResult"></textarea>
</form>
</pre>

<script>
if (!%(valid_user)d) {
  postWarning.textContent = 'Posting restricted to @chromium.org/@google.com users.';
  postSubmit.disabled = true;
}

function encodeForm(form) {
  return [].map.call(form.querySelectorAll('input[type=textbox]'), function(field) {
    return field.name + '=' + encodeURIComponent(field.value);
  }).join('&');
}

function loadResult(url, textarea) {
  textarea.value = '';
  var xhr = new XMLHttpRequest();
  xhr.open('get', url, true);
  xhr.onreadystatechange = function() {
    if (xhr.readyState === XMLHttpRequest.DONE) {
      try {
        var json = JSON.parse(xhr.responseText);
        textarea.value = JSON.stringify(json, null, '  ')
      } catch (_) {
        textarea.value = xhr.responseText;
      }
    }
  }
  xhr.send();
}

postSubmit.addEventListener('click', function() {
  loadResult('/post?' + encodeForm(postForm), postResult);
});
querySubmit.addEventListener('click', function() {
  loadResult('/query?' + encodeForm(queryForm), queryResult);
});

// Add Google Analytics integration
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-55762617-13', {'siteSpeedSampleRate': 100});
ga('send', 'pageview');
</script>
